Added command&system to purge all messages up to given message#1055
Conversation
| # thus we need to paginate the amount to always be <= 100 | ||
| await channel.delete_messages(messages[i:i + 100]) | ||
| else: | ||
| messages += await channel.purge(limit=amount, check=predicate) |
There was a problem hiding this comment.
Since you've essentially written all the code needed, can we get rid of purge? It redundantly iterates message history. We already have message objects from our own history search, so let's use those. That being said, one strange thing purge does is use a single delete strategy if messages are older than 2 weeks. I don't know if that's important.
There was a problem hiding this comment.
Reason why it does single deletes is because you can't delete messages older than 14 days via bulk delete endpoint, I didn't include that edge case in the code as (at least to me) it appears unlikely for moderators to attempt and purge messages older than that.
That being said attempts of deleting the messages older than 14 days via delete_messages will raise following error:
discord.errors.HTTPException: 400 Bad Request (error code: 50034): You can only bulk delete messages that are under 14 days old.There was a problem hiding this comment.
Do you think we can do away with purge though?
There was a problem hiding this comment.
I don't think purge is necessary considering we iterate the history either way, I am all up to rewriting current system so it doesn't use purge in separate PR as it isn't exactly the point of this PR
| if message.created_at <= until_message.created_at: | ||
| # means we have found the message until which we were supposed to be deleting. | ||
| message_ids.append(message.id) | ||
| break |
There was a problem hiding this comment.
If the current message is older than until_message, then the current message should not be appended and deleted, as it's too far back. Something like this, but maybe you can come up with something more elegant:
if message.created_at < until_message.created_at:
break
messages.append(message)
if message.id == until_message.id:
message_ids.append(message.id)
break
This PR aims to close issue #1024 by implementing purging system that purges messages up until certain message specified by moderator.
The command input supports:
However, the system of deletion is completely different from the original one, due to the fact that
TextChannel.purgewouldn't otherwise support that system well enough.I'd like to hear opinions on the PR.